<template>
  <div class="query-form">
    <el-form ref="queryForm" :model="queryForm" :inline="true">
      <el-form-item prop="type">
        <el-select
          v-model="queryForm.type"
          placeholder="供需类型"
          clearable
          size="small"
        >
          <el-option
            v-for="item in typeOptions"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item prop="title">
        <el-input
          v-model="queryForm.title"
          placeholder="标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item prop="companyName">
        <el-input
          v-model="queryForm.companyName"
          placeholder="企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item prop="status">
        <el-select
          v-model="queryForm.status"
          placeholder="状态"
          clearable
          size="small"
        >
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery">查询</el-button>
        <el-button type="warning" @click="handleReset">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {
  getTypeOptions,getStatusOptions
} from '@/api/supply-shop/overview'

export default {
  name: 'SupplyShopQueryForm',
  data() {
    return {
      queryForm: {
        title: '',
        companyName: '',
        type: undefined,
        status: undefined
      },
      typeOptions: [],
      statusOptions: []
    }
  },
  created() {
    getTypeOptions().then((response) => {
      this.typeOptions = response.data
    })
    getStatusOptions().then((response) => {
      this.statusOptions = response.data
    })
  },
  methods: {
    handleQuery() {
      this.$emit('query', this.queryForm)
    },
    handleReset() {
      this.$refs['queryForm'].resetFields()
      this.handleQuery()
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
